<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>三会一课</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <script src="/js/jquery.min.js"></script>
    <script src="/js/assets/amazeui.widgets.helper.min.js"></script>
    <script src="/js/assets/amazeui.widgets.helper.js"></script>
    <script src="/js/assets/amazeui.ie8polyfill.min.js"></script>
    <script src="/js/assets/amazeui.ie8polyfill.js"></script>
    <script src="/js/assets/amazeui.min.js"></script>
    <script src="/js/assets/amazeui.js"></script>

    <link rel="stylesheet" type="text/css" href="/css/assets/amazeui.min.css">
    <link rel="stylesheet" type="text/css" href="/css/assets/amazeui.css">
    <style>
        .loadmore{
            text-align: center;
            height: 0px;
            line-height: 30px;
            background-color: #999;
            display: none;
            transition: height 1s;
            -moz-transition: height 1s; /* Firefox 4 */
            -webkit-transition: height 1s;  /* Safari 和 Chrome */
            -o-transition: height 1s;   /* Opera */

        }
        .loadmore.show{
            display: block;
            height: 30px;
        }
    </style>
</head>
<body>
    <div class="container">
        <input type="text" id="page" value="0" hidden="hidden">
        <ul id="general" class="general">

        </ul>
        <div class="loadmore">上拉加载更多</div>
    </div>
</body>
<script>
    var page=document.getElementById("page").value;
    $(function() {
        loadGeneral(page);

        var loadFlag = false;
        var _stary,_endy;
        $(".container").on("touchend",function(){

            $(".container").stop().animate({top:0},80);
            if($(this).height()+$(this).scrollTop()>=$(".container ul").height() && !loadFlag){
                loadFlag = true;
                $(".loadmore").addClass("show");
                $(this).scrollTop(100000000000);
                page++;
                console.log(page);
                loadGeneral(page);
                setTimeout(function(){
                    $(".loadmore").removeClass("show");
                    loadFlag = false;
                },1000);
            }
        });
        $(".container").on("touchstart",function(e){
            var _touch = e.originalEvent.targetTouches[0];
            _stary= _touch.pageY;
        });
        $(".container").on("touchmove",function(e){
            var _touch = e.originalEvent.targetTouches[0];
            _endy= _touch.pageY;
            if($(this).height()+$(this).scrollTop()>=$(".container ul").height()){
                var current_y = _endy - _stary;
                $(".container").animate({top:current_y/3},5);
            }
        });
    });

    function loadGeneral(){
        $.ajax({
            type:"get",//访问url类型（get,post）
            url:"getTeamByMaxTotal",//url地址
            async:false,//是否异步加载，true为异步加载，false为同步加载
            data : {
                page:page,
            },//发送数据
            dataType : "text",//数据类型
            success :function(result){//成功返回
                result=eval("("+result+")");
                console.log(result);
                var general=document.getElementById("general");
                for(var i=0;i<result.length;i++){
                    var readYOS="";
                    if(result[i][5]!=null){
                        readYOS="已读";
                    }
                    var total="0";
                    if(result[i][4]!=null){
                        total=result[i][4];
                    }
                    var li = document.createElement("li");
                    li.className = "teamDetail";
                    li.innerHTML = "" +
                        "<a href='/getStudyDetail?id=" + result[i][0] + "' " +
                        "<div class='am-g'>" +
                        "<div class='am-u-sm-10'>" +
                        "<div class='title'>" + result[i][1] + "" +
                            "<p class='detail'>"+result[i][2]+"&nbsp;&nbsp;&nbsp;阅读数："+total+"</p>" +
                        "</div>" +
                        "</div>" +
                        "<div class='am-u-sm-2'>" +
                        "<img src='" + result[i][3] + "' style='height: 50px;width:50px' class='titleImg'/>" +readYOS+
                        "</div>" +
                        "</div>"+
                        "<hr>"+
                        "</a>";
                    general.appendChild(li);
                }
            },
            error : function(errorMsg) {//返回失败

            }
        });
    }
</script>
</html>